<!--
 * @Author: Pure <305737824@qq.com>
 * @CreateTime: 2021-12-28 15:03:28
 * @LastEditors: Pure <305737824@qq.com>
 * @LastEditTime: 2021-12-28 15:10:49
 * @Description:用户下拉框(多选)
-->
<template>
  <pure-draggable-select
    v-model="selectedData"
  >
    <el-option
      v-for="(item, index) in list"
      :key="index"
      :label="item.name"
      :value="item.id"
    />
  </pure-draggable-select>
</template>

<script>

import EngineerApi from '../api';
export default {
  name: 'EngineerMultiSelect',
  components: {
    PureDraggableSelect: () => import('@/components/select/draggableSelect'),
  },
  props: {
    value: {
      type: String,
      default: null,
    },
  },
  data() {
    return {
      list: [],
    };
  },
  computed: {
    selectedData: {
      set(newVal) {
        this.$emit('input', newVal.join(','));
        this.$emit('change');
      },
      get() {
        return this.value ? this.value.split(',').map(item => Number(item)) : [];
      },
    },
  },
  async created() {
    try {
      const { list, } = await EngineerApi.list({ states: '1', });
      this.list = list;
    } catch (error) {
      console.log(error);
    }
  },
};
</script>

<style lang="scss" scoped>

</style>
